package com.example.servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/chinese")
public class ServletChinese extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //设置响应所对应的编码集，使其可以识别中文
        resp.setContentType("text/html;charset=UTF-8");

//        resp.getWriter().print("欢迎来到我的网站。");
//
//        //请求转发
//        RequestDispatcher requestDispatcher = req.getRequestDispatcher("/index.jsp");
//
//        requestDispatcher.forward(req,resp);

//        String username = req.getParameter("username");
//        String password = req.getParameter("password");
//
//        resp.getWriter().print(username);
//        resp.getWriter().print(password);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //设置响应所对应的编码集，使其可以识别，传递中文
        resp.setContentType("text/html;charset=UTF-8");
        //设置响应所对应的编码集，使其可以识别，传递中文
        req.setCharacterEncoding("UTF-8");


        String username = req.getParameter("username");
        String password = req.getParameter("password");

        resp.getWriter().print(username);
        resp.getWriter().print(password);
    }
}
